<?php
/**
 * Created by PhpStorm.
 * User: simon
 * Date: 2016/11/29
 * Time: 11:02
 */

namespace App\Weixin;


use Illuminate\Support\Str;
use p5\objects\StringUtils;

class EventKeyUtils
{

    /**
     * 判断 key 是否是渠道推广的 key
     * @param $key string
     * @return bool
     */
    static public function isPromotionKey($key)
    {
        return strlen($key) <= 6 && $key * 1 < 100000;
    }

    /**
     * 判断是否是登录二维码
     * @param $key
     * @return bool
     */
    public static function isLoginKey($key)
    {
        return strlen($key) === 9 && substr($key, 0, 2) == "10";
    }

    public static function createLoginKey()
    {
        // 1 开头的专门用于扫码登录
        return self::createKey("10");
    }

    public static function isBindKey($key)
    {
        // 专门用于绑定账号的
        return strlen($key) === 9 && substr($key, 0, 2) == "11";
    }

    public static function createBindKey()
    {
        // 1 开头的专门用于扫码登录
        return self::createKey("11");
    }

    public static function createKey($prefix)
    {
        return $prefix . StringUtils::random_nums(9 - strlen($prefix));
    }
}